package yaner.hotel.manager.resource.mapper.impl;

import org.springframework.stereotype.Component;
import yaner.hotel.manager.common.dto.roomType.RoomTypeAddDto;
import yaner.hotel.manager.common.dto.roomType.RoomTypeUpdateDto;
import yaner.hotel.manager.common.utils.SnowUtils;
import yaner.hotel.manager.common.vo.RoomTypeVo;
import yaner.hotel.manager.resource.entity.RoomType;
import yaner.hotel.manager.resource.mapper.IRoomTypeMapper;

import java.util.Date;
import java.util.Objects;

@Component
public class RoomTypeMapperImpl implements IRoomTypeMapper {
    @Override
    public RoomTypeVo toVo(RoomType roomType) {
        Objects.requireNonNull(roomType, "RoomTypeMapperImpl toVo roomType is null");
        return RoomTypeVo.builder()
                .roomTypeDesc(roomType.getRoomTypeDesc())
                .roomTypeId(roomType.getRoomTypeId())
                .roomTypeName(roomType.getRoomTypeName())
                .roomTypeCode(roomType.getRoomTypeCode())
                .roomTypeStatus(roomType.getRoomTypeStatus())
                .build();
    }

    @Override
    public RoomType toAddEntity(RoomTypeAddDto roomTypeAddDto) {
        Objects.requireNonNull(roomTypeAddDto, "RoomTypeMapperImpl toAddEntity roomTypeAddDto is null");
        return RoomType.builder()
                .roomTypeDesc(roomTypeAddDto.getRoomTypeDesc())
                .roomTypeId(SnowUtils.nextId())
                .roomTypeName(roomTypeAddDto.getRoomTypeName())
                .roomTypeCode(roomTypeAddDto.getRoomTypeCode())
                .roomTypeStatus(roomTypeAddDto.getRoomTypeStatus())
                .createTime(new Date())
                .updateTime(new Date())
                .build();
    }

    @Override
    public RoomType toUpdateEntity(RoomTypeUpdateDto roomTypeUpdateDto) {
        Objects.requireNonNull(roomTypeUpdateDto, "RoomTypeMapperImpl toUpdateEntity roomTypeUpdateDto is null");
        return RoomType.builder()
                .roomTypeDesc(roomTypeUpdateDto.getRoomTypeDesc())
                .roomTypeId(roomTypeUpdateDto.getRoomTypeId())
                .roomTypeName(roomTypeUpdateDto.getRoomTypeName())
                .roomTypeCode(roomTypeUpdateDto.getRoomTypeCode())
                .roomTypeStatus(roomTypeUpdateDto.getRoomTypeStatus())
                .createTime(roomTypeUpdateDto.getCreateTime())
                .updateTime(new Date())
                .build();
    }
}
